﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ARS.Control.Custom.Entity.Widget;

namespace ARS.Control.Custom.Entity.Fields
{
    public class RequestQueryField:HiddenInputField
    {
        public RequestQueryField():base(true)
        {
            base.Widget = new Forms.RequestQueryForm();
        }

        /// <summary>
        /// 显示tr行
        /// </summary>
        public bool IsTrShow
        {
            get;
            set;
        }
        /// <summary>
        /// 查询显示值
        /// </summary>
        public string TrShowSql
        {
            get;
            set;
        }

        /// <summary>
        /// 获取某个属性的值
        /// </summary>
        public string RequestKeyName
        {
            get;
            set;
        }
        /// <summary>
        /// 加密主键
        /// </summary>
        public bool IsEncryptKey
        {
            get;
            set;
        }

        /// <summary>
        /// 取值列表
        /// </summary>
        public string ValueList
        {
            get;
            set;
        }
        /// <summary>
        /// 获取真实Value值
        /// </summary>
        /// <returns></returns>
        public string GetValue()
        {
            string value = HttpContext.Current.Request.QueryString[this.RequestKeyName];
            if (this.IsEncryptKey)
            {
                value = ARS.PublicTool.DataHandle.Encrypt.DecryptString(value);
            }
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }
            else
            {
                if (this.ValueList != null)
                {
                    string[] valueList =
                        this.ValueList.Split(new[] { "|" },
                            StringSplitOptions.None);
                    //this.Field.Value = valueList[Int32.Parse(value)];
                    return valueList[Int32.Parse(value)];
                }
                else
                {
                    //this.Field.Value = value;
                    return value;
                }
            }
        }

        public override void InitInputValue(EntityBaseControl entityBaseControl)
        {
            this.Value = this.GetValue();
        }
    }
}
